package com.yumi.shizhan;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterThrowing;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class LoggerAspect {
    private static final Logger LOGGER = LoggerFactory.getLogger(LoggerAspect.class);

    @AfterThrowing(throwing = "e", pointcut = "execution(* com.yumi.shizhan..*.serve(..))")
    public void logIfError(JoinPoint jp, RuntimeException e) {
        String errorType = "未知错误";
        if (e instanceof PaperJamException) {
            errorType = "卡纸异常";
        } else if (e instanceof InkEmptyException) {
            errorType = "墨盒无墨异常";
        }

        LOGGER.error("【{}】方法: {}，参数: {}，原因: {}",
                errorType,
                jp.getSignature().getName(),
                jp.getArgs(),
                e.getMessage());
    }
}